/*
 * @Author: lyx 2858535420@qq.com
 * @Date: 2022-10-10 22:31:07
 * @LastEditors: lyx 2858535420@qq.com
 * @LastEditTime: 2023-04-27 10:35:38
 * @FilePath: /antd-vue2-template/src/mock/services/auth.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Mock from 'mockjs2';
import { builder, getBody } from '../util';

const username = ['admin', 'super'];
// 强硬要求 ant.design 相同密码
// '21232f297a57a5a743894a0e4a801fc3',
const password = ['8914de686ab28dc22f30d3d8e107ff6c', '21232f297a57a5a743894a0e4a801fc3']; // admin, ant.design

const login = (options) => {
  const body = getBody(options);
  console.log('mock: body', body);
  if (!username.includes(body.username) || !password.includes(body.password)) {
    return builder({ isLogin: true }, '账户或密码错误', 401);
  }

  return builder({
    'id': Mock.mock('@guid'),
    'name': Mock.mock('@name'),
    'username': 'admin',
    'password': '',
    'avatar': 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
    'status': 1,
    'telephone': '',
    'lastLoginIp': '27.154.74.117',
    'lastLoginTime': 1534837621348,
    'creatorId': 'admin',
    'createTime': 1497160610259,
    'deleted': 0,
    'roleId': 'admin',
    'lang': 'zh-CN',
    'token': '4291d7da9005377ec9aec4a71ea837f'
  }, '', 200, { 'Custom-Header': Mock.mock('@guid') });
};

const logout = () => {
  return builder({}, '[测试接口] 注销成功', 200);
};

const smsCaptcha = () => {
  return builder({ captcha: Mock.mock('@integer(10000, 99999)') }, '', 200);
};

const twofactor = () => {
  return builder({ stepCode: Mock.mock('@integer(0, 1)') }, '', 200);
};

Mock.mock(/\/auth\/login/, 'post', login);
Mock.mock(/\/auth\/logout/, 'post', logout);
Mock.mock(/\/account\/sms/, 'post', smsCaptcha);
Mock.mock(/\/auth\/2step-code/, 'post', twofactor);
